<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Derives a key from a password, using scrypt</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.sodium-crypto-pwhash-scryptsalsa208sha256-str.html">« sodium_crypto_pwhash_scryptsalsa208sha256_str</a></li>
      <li style="float: right;"><a href="function.sodium-crypto-pwhash-str-needs-rehash.html">sodium_crypto_pwhash_str_needs_rehash »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.sodium.html">Sodium 函数</a></li>
    <li>Derives a key from a password, using scrypt</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.sodium-crypto-pwhash-scryptsalsa208sha256" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_crypto_pwhash_scryptsalsa208sha256</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">sodium_crypto_pwhash_scryptsalsa208sha256</span> &mdash; <span class="dc-title">Derives a key from a password, using scrypt</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-crypto-pwhash-scryptsalsa208sha256-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sodium_crypto_pwhash_scryptsalsa208sha256</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$salt</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$opslimit</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$memlimit</code></span><br>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   This is the scrypt counterpart to <span class="function"><a href="function.sodium-crypto-pwhash.html" class="function">sodium_crypto_pwhash()</a></span>.
  </p>
  <p class="para">
   A common reason to use this particular function is to derive the seeds for cryptographic keys from a password and salt,
   and then use these seeds to generate the actual keys needed for some purpose (e.g. <span class="function"><a href="function.sodium-crypto-sign-detached.html" class="function">sodium_crypto_sign_detached()</a></span>).
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-crypto-pwhash-scryptsalsa208sha256-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">length</code></dt>

    <dd>

     <p class="para">
      The length of the password hash to generate, in bytes.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">password</code></dt>

    <dd>

     <p class="para">
      The password to generate a hash for.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">salt</code></dt>

    <dd>

     <p class="para">
      A salt to add to the password before hashing. The salt should be unpredictable, ideally generated from a good random number source such as <span class="function"><a href="function.random-bytes.html" class="function">random_bytes()</a></span>, and have a length of at least <strong><code>SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES</code></strong> bytes.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">opslimit</code></dt>

    <dd>

     <p class="para">
      Represents a maximum amount of computations to perform. Raising this number will make the function require more CPU cycles to compute a key. There are some constants available to set the operations limit to appropriate values depending on intended use, in order of strength: <strong><code>SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE</code></strong> and <strong><code>SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_SENSITIVE</code></strong>.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">memlimit</code></dt>

    <dd>

     <p class="para">
      The maximum amount of RAM that the function will use, in bytes. There are constants to help you choose an appropriate value, in order of size: <strong><code>SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE</code></strong> and <strong><code>SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_SENSITIVE</code></strong>. Typically these should be paired with the matching <code class="parameter">opslimit</code> values.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-pwhash-scryptsalsa208sha256-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   A string of bytes of the desired length.
  </p>
 </div>



</div></div></div></body></html>